package com.ym.livedemo.api

import android.content.Context
import android.util.Log
import com.ym.livedemo.Constant
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class ReceivedCookiesInterceptor(val context: Context) : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {
        val originalResponse = chain.proceed(chain.request())

        if (!originalResponse.headers("Authorization").isEmpty()) {
            val cookies = mutableListOf<String>()

            for (header in originalResponse.headers("Authorization")) {
                cookies.add(header)
            }
            if (cookies[0].isNotBlank()) {
                Log.e("TAG", "intercept: " +  cookies[0])
                Constant.TOKEN = cookies[0]

            }
        }

        return originalResponse
    }
}
